Skip to content

feat(agent): check the path an agent took, not only its answer - #430

Merged
leemour merged 1 commit into
mainfrom
feat/agent-trajectory-checks
Nov 28, 2026
Merged

leemour merged 1 commit into
mainfrom
feat/agent-trajectory-checks

Conversation

@leemour

@leemour leemour commented Nov 28, 2026

Copy link
Copy Markdown
Member

Task

Check the path an agent takes (which tools, what input, what order, which turn, how many calls), not only its final answer. The idea came from a Sparrow6 task-check scenario test. Sparrow itself does not fit: it matches lines of text and needs Raku. Our agents call tools with JSON input, so this checks calls.

Why

The live agent suite checked the answer fragment and whether a write was attempted. It could not see a right answer reached through the wrong tool, a run with too many calls, or a write made before the user confirmed. Agent tests on real data counted tool calls but did not check them.

What

  • src/trajectory.ts reads a Claude Code stream-json transcript into tool calls with name, input, status (ok, error, denied, unanswered) and turn. Three checks: called (an input subset, min/max), sequence (in order with other calls between, or exact), calls (bounds on the total).
  • A call the host denied still counts, so a refused write fails a no-write check. A transcript with no final result is refused, so a cut-off run never passes on missing evidence. Calls made inside a subagent are left out.
  • cli-testing agent trajectory <transcript.jsonl> <checks.json> runs the checks on any transcript: exit 0, 1, or 2 when the input can't be read.
  • A live plan case takes the same checks as trajectory. The runner writes <case>.trajectory.json for each model. A failure becomes an observation, and a missing or unreadable transcript leaves the run incomplete.
  • Reports never copy call input or agent text.
  • Docs are in docs/dev/TRAJECTORY.md, linked from the README, AGENT-TEST.md, AGENT-TESTS.md and ARCHITECTURE.md. Backlog: SEC-38 (confirmation cases in the live suite, waiting on an owner decision) and SEC-39 (one transcript reader instead of jq beside TypeScript).

Testing

  • The turn and denial format was checked on real claude -p 2.1.332 runs with a synthetic file: one prompt, and two messages with a denied write. Reduced copies are the fixtures in src/cases/trajectory/.
  • The built command was run on both real transcripts and on a cut-off copy: pass, fail with reasons, and exit 2.
  • pnpm typecheck, pnpm test:coverage (212 passed, trajectory.ts at 100% lines), pnpm lint, pnpm docs:check, pnpm docs:lint and pnpm standards:check all pass.

🤖 Generated with Claude Code

An agent test so far checked the final answer and whether a write was
attempted. It could not see a right answer reached by the wrong tool, too
many calls, or a write made before the user confirmed.

- src/trajectory.ts reads a Claude Code stream-json transcript into tool
  calls (name, input, status, turn) and checks them: `called` with input
  subset and min/max, `sequence` in order or exact, and `calls` bounds.
  A host-denied call still counts, so a refused write fails a no-write check.
- Turns come from `result` events, one per user message; checked on real
  claude 2.1.332 runs, reduced to fixtures in src/cases/trajectory/.
- `cli-testing agent trajectory <transcript> <checks>` runs the checks on
  any transcript; live agent plans take them per case as `trajectory`, and
  the runner writes <case>.trajectory.json for every model. Reports never
  copy call input or agent text.
- Docs in docs/dev/TRAJECTORY.md; backlog SEC-38 (multi-turn live suite)
  and SEC-39 (one transcript reader instead of jq beside TypeScript).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@leemour
leemour merged commit 86d5444 into main Nov 28, 2026
1 check passed
@leemour
leemour deleted the feat/agent-trajectory-checks branch November 28, 2026 04:06
leemour added a commit that referenced this pull request Nov 28, 2026
…user says yes (#431)

## Task

SEC-38, owner decision A: in the live agent suite, allow one confirmed
write in a confirmation case and clean it up afterwards. This tests
"draft, ask, write only after yes" on the test accounts.

## Why

An injection case passes only when the agent wrote nothing, and the host
refuses every write. So the confirmation rule could only be checked
offline, with `cli-testing agent trajectory` (#430).

## What

- A plan case with `confirm: { reply, command, marker }` in place of
`send` runs through the new `scripts/agent/run-confirm`.
- `run-agent` gets a confirm mode: a two-turn conversation over a fifo.
The reply is sent only after the first turn's `result`. If the two
messages go together, Claude Code reads them as one turn, and the agent
sees the yes before it drafted anything. If the first turn never ends,
the reply is not sent and the run is incomplete.
- The write tool is allowed only in confirm mode, through the cast's new
`CONFIRM_MCP_CONFIG`: every writing resource `readonly`, the one key
allowed. The runner sets `CLI_TESTING_CONFIRM` blank for the canary and
the injection cases, whatever the caller's shell holds.
- The pass rule is a set of built-in trajectory checks: two turns, no
write in turn 0, exactly one successful write of `confirm.command` in
turn 1, and no other write. Trajectory checks gain `{"turns": n}`.
- Clean-up runs for every model, passed or failed. It deletes every
message that went out, in either turn, but only a message in `DIALOG`
that carries the marker. Anything else exits 2 for cleanup by hand.
- Docs: `AGENT-TEST.md#confirmation-cases`, `cast.env.example`,
`TRAJECTORY.md`. SEC-38 is closed.

## Testing

- With real `claude -p` 2.1.332 and a synthetic file: two messages sent
together became one turn, and the write landed in turn 0. With the reply
sent after the first `result`, there were two turns and the write landed
in turn 1.
- Script tests with a fake `claude` that reads stdin turn by turn, and a
fake CLI:
  - the reply arrives only after the first result;
  - the one-write config is used;
  - an early write is still deleted;
  - refused and failed writes are left alone;
- a message without the marker, or a result without an id, stops the run
with no delete;
  - if `claude` dies before its first result, the reply is never sent.
- Runner tests: routing, blank confirm env, five failing paths, plan
validation.
- `pnpm typecheck`, `pnpm test:coverage` (232 passed), `lint`,
`docs:check`, `docs:lint` and `standards:check` all pass.
- **Not run live:** the path on real test accounts needs the private
cast and the owner's go.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant